package com.cf.back.permission.controller;

import com.cf.user.login.LocalUserHolder;
import com.cf.user.login.model.UserInfo;
import com.cf.user.permission.service.SystemPermissionService;
import com.cf.user.permission.vo.Menu;
import com.cf.web.RequiredLogin;
import com.cf.web.controller.PageController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * game-server-IndexController
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/5/31 上午 10:52
 */

@RequestMapping
public class IndexController extends PageController {

    @Autowired
    private SystemPermissionService permissionService;

    @Override
    protected String getPageDir() {
        return "index";
    }

    @RequiredLogin
    @RequestMapping("/index")
    public String index(HttpServletRequest httpServletRequest) {
        UserInfo userInfo = LocalUserHolder.userInfo();
        if (userInfo != null) {
            List<Menu> userMenu = permissionService.getUserMenu(userInfo.getId());
            httpServletRequest.setAttribute("menus", userMenu);
            httpServletRequest.setAttribute("user", userInfo);
        }
        return getPageDir() + "/index";
    }

}
